<template>
  <!--会签管理-单据申请-劳务结算弹窗-表单-->
  <a-spin :spinning="confirmLoading">
    <j-form-container class="scroll-view" style="height: 600px;" :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row style="margin-bottom: 20px;">
          <a-col :span="12">
            <span style="font-size: 20px;font-weight: bold;">劳务结算</span>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title" style="margin-bottom: 10px;">
              <a-input v-model="model.title" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId" style="margin-bottom: 10px;">
              <a-select :options="levelOneOptions" placeholder="请选择项目" v-model="model.projectId">
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierId" style="margin-bottom: 10px;">
              <a-select placeholder="请选择班组" :options="levelTwoOptions" v-model="model.supplierId">
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractNumber" style="margin-bottom: 10px;">
              <a-input v-model="model.contractNumber" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="结算时间" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="period"
              style="margin-bottom: 10px;margin-left: 20px;">
              <div style="display: flex;align-items: center;">
                <a-select style="width: 314px;margin: 0 52px 0 2px;" placeholder="" :options="period"
                  v-model="model.period">
                </a-select>
                <j-date v-model="model.startTime" :showTime="true" date-format="YYYY-MM-DD " style=""
                  placeholder="请选择开始时间"></j-date>
                <div style="width: 10px;margin: 0 10px;">~</div>
                <j-date v-model="model.endTime" :showTime="true" date-format="YYYY-MM-DD" style=""
                  placeholder="请选择结束时间"></j-date>
              </div>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="结算项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settlementAccount" style="margin-bottom: 10px;">
              <a-input v-model="model.settlementAccount" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="本期完成量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentCompletion" style="margin-bottom: 10px;">
              <a-input v-model="model.currentCompletion" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="扣款或奖罚" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rewardAndPunish" style="margin-bottom: 10px;">
              <a-input v-model="model.rewardAndPunish" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="本期结算金额:" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="currentSettlementAmount" style="margin-bottom: 10px;">
              <a-input v-model="model.currentSettlementAmount" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="累计结算金额:" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="accumulatedSettlementAmount" style="margin-bottom: 10px;">
              <a-input style="" v-model="model.accumulatedSettlementAmount" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
              style="margin-bottom: 10px;margin-left: 20px;">
              <textarea v-model="model.remark" cols="100" rows="3" style="width: 93%;"></textarea>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="附件资料" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="attachment"
              style="margin:0 60px 10px 20px;">
              <j-upload v-model="model.attachment"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>

      </a-form-model>
    </j-form-container>
    <!-- <a-button @click="save" type="primary">保存</a-button> -->

  </a-spin>
</template>

<script>
  import {
    httpAction,
    getAction
  } from '@/api/manage'
  import {
    validateDuplicateValue
  } from '@/utils/util'

  export default {
    name: 'WtBrandForm',
    components: {},
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false,
      },
    },
    data() {
      return {
        model: {
          countersignTemplateId: '',
          attachment: ''
        },
        period: [{
            value: 1,
            label: "第1期"
          },
          {
            value: 2,
            label: "第2期"
          },

          {
            value: 3,
            label: "第3期"
          }, {
            value: 4,
            label: "第4期"
          },
          {
            value: 5,
            label: "第5期"
          },

          {
            value: 6,
            label: "第6期"
          }, {
            value: 7,
            label: "第7期"
          },
          {
            value: 8,
            label: "第8期"
          },

          {
            value: 9,
            label: "第9期"
          }, {
            value: 10,
            label: "第10期"
          },
          {
            value: 11,
            label: "第11期"
          },

          {
            value: 12,
            label: "第12期"
          }, {
            value: 13,
            label: "第13期"
          },
          {
            value: 14,
            label: "第14期"
          },

          {
            value: 15,
            label: "第15期"
          }, {
            value: 16,
            label: "第16期"
          },
          {
            value: 17,
            label: "第17期"
          },

          {
            value: 18,
            label: "第18期"
          }, {
            value: 19,
            label: "第19期"
          },
          {
            value: 20,
            label: "第20期"
          },

          {
            value: 21,
            label: "第21期"
          }, {
            value: 22,
            label: "第22期"
          },
          {
            value: 23,
            label: "第23期"
          },

          {
            value: 24,
            label: "第24期"
          }
        ],
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 5
          },
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          },
        },
        labelCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 2
          },
        },
        wrapperCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 22
          },
        },
        confirmLoading: false,
        validatorRules: {},
        levelOneOptions: [],
        levelTwoOptions: [],
        treeData: [],
        treeData1: [],
        fileList: [],
        url: {
          add: '/countersign/wtCountersignServiceSettlement/add',
          edit: '/wtBrand/edit',
          queryById: '/wtBrand/queryById',
        },
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
    },
    created() {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model))
    },
    methods: {
      loadTree() {
        var that = this
        getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
          if (res.success) {

            this.treeData = []
            let treeList = res.result
            for (let a = 0; a < treeList.length; a++) {
              let temp = treeList[a]
              temp.isLeaf = temp.leaf
              this.treeData.push(temp)
            }

            this.levelOneOptions = [...this.treeData].map((v) => {
              return {
                ...v,
                value: v.id,
                label: v.departName,
              }
            })


          }
        })
        getAction(`/wtSupplier/list?type=1`).then((res) => {
          if (res.success) {

            this.treeData1 = []
            let treeList = res.result.records
            for (let a = 0; a < treeList.length; a++) {
              let temp = treeList[a]
              temp.isLeaf = temp.leaf
              this.treeData1.push(temp)
            }

            this.levelTwoOptions = [...this.treeData1].map((v) => {
              return {
                ...v,
                value: v.id,
                label: v.name,
              }
            })


          }
        })
      },
      add(record) {
        //this.edit(this.modelDefault)
        this.model.countersignTemplateId = record.id;
        this.edit();
      },
      edit(record) {
        //this.model = Object.assign({}, record)
        this.visible = true
        this.loadTree()
      },
      submitForm(record) {
        const that = this
        if (!this.model.attachment) {
          that.$message.warning('附件资料不能为空,请上传')
        } else {
          // 触发表单验证
          this.$refs.form.validate((valid) => {
            if (valid) {
              that.confirmLoading = true
              let httpurl = ''
              let method = ''
              that.model.status = record;
              // debugger
              httpAction('/countersign/wtCountersignServiceSettlement/add', this.model, 'POST')
                .then((res) => {
                  if (res.success) {
                    that.$message.success(res.message)
                    that.$emit('ok')
                  } else {
                    that.$message.warning(res.message)
                    that.$emit('error')
                  }
                })
                .finally(() => {
                  that.confirmLoading = false
                })
            }
          })
        }
        
      },
    },
  }
</script>
<style scoped>
  .scroll-view {
    overflow: auto;
    overflow-y: scroll;
  }
</style>